<?php

namespace app\model;

class Qrcode
{

    function getUserQrcode($user_id, $page)
    {
        $scene = $user_id;
        return $this->getQrcode($scene, $page);
    }
    function getGoodsQrcode($goodsid, $user_id, $page)
    {
        $scene = "{$goodsid},{$user_id}";
        return $this->getQrcode($scene, $page);
    }
    function getOrderQrcode($orderid, $page)
    {
        $scene = $orderid;
        return $this->getQrcode($scene, $page);
    }

    function getQrcode($scene, $page, $width = 230)
    {

        $app =  Wxmini::make();
        $response = $app->app_code->getUnlimit($scene, [
            'page'  => $page,
            'width' => $width,
        ]);

        if ($response instanceof \EasyWeChat\Kernel\Http\StreamResponse) {
            $filename = $response->save(config('filesystem.disks.public.root'), 'qrcode' . md5(base64_encode(time())) . '.jpg');
        }
        return toimg('samos/public/uploads/'.$filename);

    }
}
